<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>应用模块添加</title>
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/layui/css/layui.css" />
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/index.css" />
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/dtree/dtree.css" />
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/dtree/font/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/darkBlue.css"/>
</head>
<body>
<div class="page-content-wrap">
    <form class="layui-form">
        <div class="layui-tab" style="margin:0 50px 70px 30px;">
            <div class="layui-tab-content">
                <div class="layui-tab-item"></div>
                <div class="layui-tab-item layui-show">
                    <input type="hidden" class="form-control id" id="id" name="id" value="${sysAppModule.id}" />
                    <div class="layui-form-item">
                        <label class="layui-form-label">应用名称：</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" required  lay-verify="required" placeholder="请输入应用名称" value="${sysAppModule.name}" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">应用代码：</label>
                        <div class="layui-input-block">
                            <input type="text" name="code" required lay-verify="required" placeholder="请输入应用描述" value="${sysAppModule.code}" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">启用状态：</label>
                        <div class="layui-input-block">
                            <select name="status" id="status">

                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">应用描述：</label>
                        <div class="layui-input-block">
                            <textarea class="layui-textarea" name="description" lay-verify="content" placeholder="请输入应用描述" id="LAY_demo_editor">${sysAppModule.description}</textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;菜单权限：</label>
                        <div class="layui-input-block h240 overauto scrollbar">
                            <input type="hidden" name="menuIds" id="menuIds" value="${sysAppModule.menuIds}" />
                            <ul id="menu" class="dtree" data-id="0" data-selector-type="mult"></ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-pop-btn">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="submitBtn">提交</button>
            <button type="button" id="cancel" class="layui-btn layui-btn-primary">取消</button>
            <button type="button" style="display: none;" id="save" class="layui-btn layui-btn-primary"></button>
        </div>
    </form>
</div>

<script src="${s.base}/lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="${s.base}/js/common.js" type="text/javascript" charset="utf-8"></script>
<script>
    layui.use(['form', 'jquery', 'laydate', 'layer', 'dialog','baseutil','page','dtreeUtil','validUtil'], function() {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery,
            baseutil = layui.baseutil,
            dialog = layui.dialog,
            dtreeUtil = layui.dtreeUtil,
            validUtil=layui.validUtil;
        var page = layui.page;
        page.initDict("base_status",function (dictData) {
            page.showDict($("#status"), page.aceeptDictContentList(dictData, "base_status"), "",'${sysAppModule.status}');
        });
        var  menuIds='${sysAppModule.menuIds}';
        dtreeUtil.pageDtree("#menu","/sysMenu/dTreeList",true,function (data,obj) {
            if(!isBlank(menuIds)){
                dtreeUtil.chooseDataInit("menu",menuIds);
            }
        });
        //监听提交
        //监听提交
        form.on('submit(submitBtn)', function(data){
            dtreeUtil.getCheckbarNodesParam("menu",function (params) {
                if(params.length == 0){
                    dialog.msg("请至少选择一个权限");
                    return false;
                }

                var ids = [];
                for(var key in params){
                    var param = params[key];
                    ids.push(param.nodeId);
                }
                data.field.menuIds=ids.join(",");
                if( !validUtil.isLength(data.field.code,8)){
                    dialog.msg("应用代码长度必须为8的倍数");
                    return false;
                }

                baseutil.post("/sysAppModule/addOrUpdate",data.field,function (result) {
                    dialog.msg(result.data);
                    $("#save").click();
                });
            })
            return false;
        });
    });
</script>
</body>

</html>